load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin
  fils = systemfunc("ls "+"data/pr_pc1_1951-2020_JJAS_piControl*.nc");timeseries derived from piControl simulations
  fs   = addfiles(fils,"r")
  ListSetType(fs,"cat")

  ts = fs[:]->ts
  ts = ts-conform(ts,dim_avg_n_Wrap(ts,1),0)

  n = dimsizes(ts)

  ts_5yr = new((/n(0),14/),"float")
  do i=0,13
    ts_5yr(:,i) = dim_avg_n_Wrap(ts(:,i*5:i*5+4),1); nonoverlapping continuous 5-year average
  end do 

  foutname = "data/ts_noise_5yr_piControl.nc" ; noise for piControl simulations
  system("rm -rf "+foutname)
  fout=addfile(foutname,"c")
  fout->noise=ts_5yr 

end 